//
//  DatabaseOperate.hpp
//  MMS
//
//  Created by 王翛然 on 16/8/9.
//  Copyright © 2016年 王翛然. All rights reserved.
//

#ifndef DatabaseOperate_hpp
#define DatabaseOperate_hpp

#include <iostream>
#include <mysql.h>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <memory>

class DatabaseOp
{
public:
    DatabaseOp()
    {
        mysql_init(&mysql);
        if (connect("localhost", "root", "","MMS", 3306, nullptr, 0) == false)
        {
            std::cout << "connect database failed!!!";
        }
    }
    
    bool connect(const char *host, const char *user,
                 const char *password, const char *db,
                 unsigned int port,
                 const char *unix_socket,
                 unsigned long flag);
    
    int executeSql(const std::string &sql);
    MYSQL_RES* fetchResult();
    
    ~DatabaseOp() { ::mysql_close(&mysql); }
private:
    MYSQL mysql;
};


#endif /* DatabaseOperate_hpp */
